﻿using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LianKe.DynamicFormPlugIn
{
    [Description("过滤日期动态表单插件"), HotUpdate]
    public class DateListPlugIn : AbstractDynamicFormPlugIn
    {
        public override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            List<DataColumn> filterList = new List<DataColumn>();
            filterList = JsonConvert.DeserializeObject<List<DataColumn>>(this.View.OpenParameter.GetCustomParameter("dateList").GetString());
            Entity entity = this.View.BillBusinessInfo.GetEntity("F_POSW_ReportDateList");
            DynamicObjectCollection rows = this.Model.GetEntityDataObject(entity);
            foreach (DataColumn column in filterList)
            {
                DynamicObject row = new DynamicObject(entity.DynamicObjectType);
                row["F_POSW_DateKey"] = column.ColumnName;
                row["F_POSW_DateName"] = column.Caption;
                rows.Add(row);
            }
        }
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            if (e.BarItemKey.Equals("POSW_tbReturnData"))
            {
                Entity entity = this.Model.BillBusinessInfo.GetEntity("F_POSW_ReportDateList");
                //获取单据体当前焦点行
                int curRowIndex = this.View.Model.GetEntryCurrentRowIndex("F_POSW_ReportDateList");
                var row = this.View.Model.GetEntityDataObject(entity, curRowIndex);
                this.View.ReturnToParentWindow(row);
                this.View.Close();
            }
        }
    }
}
